package com.example.designmode.prototype;

import java.io.*;

//使用序列化的方式实现深层克隆
public class ResumeSerializable implements Serializable {

    private User user;
    private String timeArea;
    private String company;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getTimeArea() {
        return timeArea;
    }

    public void setTimeArea(String timeArea) {
        this.timeArea = timeArea;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    @Override
    //实现思路 先将对象序列化之后 写入内存之中 在将对象读取出来
    public ResumeSerializable clone(){
        ResumeSerializable resumeSerializable = null;
        try {
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            ObjectOutputStream out
                    = new ObjectOutputStream(bout);
            out.writeObject(this);

            ObjectInputStream oi
                    = new ObjectInputStream(new ByteArrayInputStream(bout.toByteArray()));
            resumeSerializable = (ResumeSerializable) oi.readObject();
            return resumeSerializable;
        } catch (Exception e) {
            System.out.println("深度克隆失败");
            return resumeSerializable;
        }
    }
}
